package logic

import (
	"context"
	"errors"
	"goods_srv/models"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodsDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetGoodsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodsDetailLogic {
	return &GetGoodsDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *GetGoodsDetailLogic) GetGoodsDetail(in *goods.GetGoodsDetailRequest) (*goods.GetGoodsDetailResponse, error) {
	// todo: add your logic here and delete this line

	var err error

	var g models.Goods
	g.ID = uint(in.GoodsId)
	err = g.Detail()
	if err != nil {
		logx.Error("获取上商品详情失败")
		return nil, errors.New("获取商品详情失败")
	}

	return &goods.GetGoodsDetailResponse{
		GoodsId:    int64(g.ID),
		GoodsTitle: g.GoodsTitle,
		GoodsCover: g.GoodsCover,
		GoodsPrice: float32(g.GoodsPrice),
	}, nil
}
